package flex.cc.store.service.impl;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

import flex.cc.PublicUtil;
import flex.cc.basicinformation.dao.ValueAddedServiceProviderDao;
import flex.cc.basicinformation.entity.ValueAddedServiceProviderEntity;
import flex.cc.common.utils.HttpClientUtil;
import flex.cc.drive.dao.DriverInterfaceLogDao;
import flex.cc.drive.dto.DriverInterfaceLogEntity;
import flex.cc.medical.dao.ImportCardDao;
import flex.cc.medical.dto.entity.ImportCardEntity;
import flex.cc.store.dao.StoreActivityConfigDao;
import flex.cc.store.dao.StoreCouponDao;
import flex.cc.store.dao.StoreOrderDao;
import flex.cc.store.dao.StorePackageConfigDao;
import flex.cc.store.dao.StorePackageDao;
import flex.cc.store.dto.entity.StoreActivityConfigEntity;
import flex.cc.store.dto.entity.StoreCouponEntity;
import flex.cc.store.dto.entity.StoreOrderEntity;
import flex.cc.store.dto.entity.StorePackageConfigEntity;
import flex.cc.store.dto.entity.StorePackageEntity;
import flex.cc.store.dto.vo.ServerPackageParam;
import flex.cc.store.service.DispenseCouponService;
import flex.cc.store.util.SdSignUtil;
import flex.cc.store.util.XYSdSignUtil;
import flex.cc.system.dao.DictCodeDao;
import flex.cc.system.entity.DictCodeEntity;
import flex.cc.util.APIConfigUtil;
import flex.cc.util.DateUtil;

/**
*
* @author R
* 2021年12月15日 下午14:35:19
* @desc 统一发券业务流程实现层
*/
@Service("dispenseCouponService")
@Transactional(rollbackFor = Exception.class)
public class DispenseCouponServiceImpl implements DispenseCouponService {
    private static final Logger logger = LoggerFactory.getLogger(DispenseCouponServiceImpl.class);
    
    @Autowired
    private StorePackageDao storePackageDao;
    @Autowired
    private StoreOrderDao storeOrderDao;
    @Autowired
    private StoreCouponDao storeCouponDao;
    @Autowired
    private StorePackageConfigDao storePackageConfigDao;
    @Autowired
    private StoreActivityConfigDao storeActivityConfigDao;
    @Autowired
    private DictCodeDao dictCodeDao;
    @Autowired
    private ImportCardDao importCardDao;
    @Autowired
    private DriverInterfaceLogDao driverInterfaceLogDao;
    @Autowired
	private ValueAddedServiceProviderDao valueAddedServiceProviderDao;
    @Autowired
	private APIConfigUtil apiConfigUtil;
//    @Value("${dispensecoupon.signKey}")
//    private String dispensecouponSignKey;
//    @Value("${redeemcode.signKey}")
//    private String redeemcodeSignKey;
//    @Value("${redeemcode.source}")
//    private String source;
//    @Value("${redeemcode.apiSource}")
//    private String apiSource;
    /**
     * @description 上游统一发券接口相关业务处理
     * @param requestBodyMap 发券接口请求体
     * @return
     * @exception/throws
    */
    @Override
    public JSONObject dispenseCoupon(Map<String, Object> requestBodyMap) {
    	JSONObject jsonResult = new JSONObject();

		String service_item_code = PublicUtil.isNotEmpty(requestBodyMap.get("service_item_code")) ? requestBodyMap.get("service_item_code").toString() : null;
		
		Map<String, Object> configReqVo = new HashMap<String, Object>();
		configReqVo.put("configCode", service_item_code);
		//根据服务包配置编码 获取服务包配置信息
		List<StorePackageConfigEntity> storePackageConfigList = storePackageConfigDao.queryPackageConfig(configReqVo);
		if(storePackageConfigList == null||storePackageConfigList.size()==0){
			//如何未查出，直接返回错误信息
			logger.info("{} flex.cc.store.service.impl.DispenseCouponServiceImpl.dispenseCoupon ==> {} ==> 未查到对应服务包配置，请联系运营人员", new Date(),service_item_code);
			jsonResult.put("resultCode", "01");
			jsonResult.put("resultDesc", "服务包已失效，请联系运营人员");
			return jsonResult;
		}else{
			StorePackageConfigEntity storePackageConfigEntity = storePackageConfigList.get(0);
			//获取服务包配置禁用状态
			String status = storePackageConfigEntity.getStatus();
			//如果是禁用状态 ，直接返回错误信息
			if(status.equals("1")){
				logger.info("{} flex.cc.store.service.impl.DispenseCouponServiceImpl.dispenseCoupon ==> {} ==> 服务包已失效，请联系运营人员", new Date(),service_item_code);
				jsonResult.put("resultCode", "01");
				jsonResult.put("resultDesc", "服务包已失效，请联系运营人员");
				return jsonResult;
			}
			
			//根据服务包配置编码获取服务包内容
			Map<String, Object> activityReqVo = new HashMap<String, Object>();
			activityReqVo.put("configCode", service_item_code);
			List<StoreActivityConfigEntity> storeActivityConfigList = storeActivityConfigDao.queryActivityConfig(activityReqVo);
			//如果未查询到服务包内容，直接返回错误信息
			if(storeActivityConfigList == null||storeActivityConfigList.size()==0){
				logger.info("{} flex.cc.store.service.impl.DispenseCouponServiceImpl.dispenseCoupon ==> {} ==> 服务包已内容失效，请联系运营人员", new Date(),storePackageConfigEntity.getConfigName());
				jsonResult.put("resultCode", "01");
				jsonResult.put("resultDesc", "服务包已失效，请联系运营人员");
				return jsonResult;
			}
		}
		
		/** 2022/02/25 0025 15:47 【2.2-服务包配置需求】增值服务商卡券发放功能优化：仅允许启用状态的增值服务商发券，否则返回：服务包已失效，请联系运营人员  */
		List<String> providerList = storeActivityConfigDao.queryProviderByServiceItemCode(service_item_code);
		for (String providerId : providerList) {
			Map<String, Object> params = new HashMap<>();
			params.put("id", providerId);
			ValueAddedServiceProviderEntity oneByParams = valueAddedServiceProviderDao.getOneByParams(params);
			if (!"1".equals(oneByParams.getStatus())) {
				logger.info("{} flex.cc.store.service.impl.DispenseCouponServiceImpl.dispenseCoupon ==> {} ==> 服务包已失效，请联系运营人员", new Date(), oneByParams.getServiceName());
				jsonResult.put("resultCode", "01");
				jsonResult.put("resultDesc", "服务包已失效，请联系运营人员");
				return jsonResult;
			}
		}

		//获取签名加密方式
    	String signType = PublicUtil.isNotEmpty(requestBodyMap.get("signType")) ? requestBodyMap.get("signType").toString() : null;
    	//验签
    	//签名生成规则：
		//    	1、设所有接收到的数据为一个数组集合，将数组内的非空参数(不包括sign字段)进行对键名的升序 排列
		//    	2、将以上排序好的数组，按照顺序依次取出键值，以&符号拼接成一个字符串
		//    	3、在拼接完字符串后，再将积分商城给到的 key拼接，然后进行 MD5 加密，生成签名
    	if(signType==null||(!"MD5".equals(signType)&&!"HMACSHA256".equals(signType)&&!"AES".equals(signType))){
    		//返回发券失败异常信息
    		logger.error("request signType: "+ signType +" 加密方式有误，无法进行验签");
    		jsonResult.put("resultCode", "01");
    		jsonResult.put("resultDesc", "加密方式有误，无法进行验签");
            return jsonResult;
    	}
    	String dispensecouponSignKey = apiConfigUtil.getSYApiConfig("signKey");
    	logger.info("上游验签key值"+dispensecouponSignKey);
    	boolean isSignatureValid = SdSignUtil.isSignatureValid(requestBodyMap, dispensecouponSignKey, signType);
    	if(!isSignatureValid){
    		//返回发券失败异常信息
    		logger.error("验签失败");
            jsonResult.put("resultCode", "01");
    		jsonResult.put("resultDesc", "验签失败");
            return jsonResult;
    	}
    	// 判断客户手机号是否重复  上游请求客户手机号为空  直接返回失败  失败原因为客户手机号不可为空
        String phone = PublicUtil.isNotEmpty(requestBodyMap.get("phone")) ? requestBodyMap.get("phone").toString() : null; 
        if (!PublicUtil.isNotEmpty(phone)) {
        	logger.error("客户手机号不可为空，发券失败");
            //返回发券失败异常信息
            jsonResult.put("resultCode", "01");
    		jsonResult.put("resultDesc", "客户手机号不可为空，发券失败");
            return jsonResult;
        }
        //正则表达式 检验手机号码有效性
		Pattern p = Pattern.compile("^[1][3,4,5,6,7,8,9][0-9]{9}$");

		Matcher m = p.matcher(phone);
		boolean isValid = m.find();
        if(!isValid){
        	logger.error("客手机号为无效手机号码，发券失败");
            //返回发券失败异常信息
            jsonResult.put("resultCode", "01");
    		jsonResult.put("resultDesc", "客手机号为无效手机号码，发券失败");
            return jsonResult;
        }
        
    	// 判断车牌号是否存在  上游请求车牌号为空  直接返回失败  失败原因为车牌号不可为空
        String carNo = PublicUtil.isNotEmpty(requestBodyMap.get("carNo")) ? requestBodyMap.get("carNo").toString() : null; 
        //客户姓名
        String customerName = PublicUtil.isNotEmpty(requestBodyMap.get("name")) ? requestBodyMap.get("name").toString() : null; 
        if (!PublicUtil.isNotEmpty(carNo)) {
        	logger.error("车牌号不可为空，发券失败");
            //返回发券失败异常信息
            jsonResult.put("resultCode", "01");
    		jsonResult.put("resultDesc", "车牌号不可为空，发券失败");
            return jsonResult;
        }
        //获取orderId 
        String orderId = PublicUtil.isNotEmpty(requestBodyMap.get("orderId")) ? requestBodyMap.get("orderId").toString() : null; 
        //根据orderId判断是否在数据库中存在
        List<StorePackageEntity> storePackageList = null;
        if(orderId!=null){
        	storePackageList = storePackageDao.queryByOrderId(orderId);
        }
        if(storePackageList!=null && storePackageList.size()==0){//订单未保存则请求下游服务包发放接口
        	//车服生成服务包编码
        	String packageCodeCF = "ZXHYCF"+DateUtil.DateToString(new Date(), "yyyyMMddHHmmssSSS");
        	logger.info("车服生成服务包编码-----------------"+packageCodeCF);
        	try {
        		/**
            	 * 服务包配置  导致请求方式发生改变
            	 * 根据服务包配置产品编码 以标识码分组查询 获取不同下游请求数据
            	 */
            	Map<String, Object> reqVo = new HashMap<String, Object>();
        		reqVo.put("configCode", service_item_code);
            	List<StoreActivityConfigEntity>  activityConfigList = storeActivityConfigDao.queryActivityConfiGroup(reqVo);
            	//遍历请求不同的下游
            	for (int j = 0; j < activityConfigList.size(); j++) {
            		
            		StoreActivityConfigEntity storeActivityConfigEntity = activityConfigList.get(j);
            		//服务商
            		String provider = storeActivityConfigEntity.getProvider();
            		//获取服务商中文名称
            		Map<String, Object> params = new HashMap<String, Object>();
            		params.put("id", provider);
            		ValueAddedServiceProviderEntity serviceProviderEntity = valueAddedServiceProviderDao.getOneByParams(params);
            		String providerCN = serviceProviderEntity.getServiceName();
            		
            		//标识码 (盛大模板id)
            		String formCode = storeActivityConfigEntity.getFormCode();
            		
            		if(PublicUtil.isEmpty(formCode)){ // 目前医护类比较特殊 无需请求下游
            			HashMap<String, String> resultMap = generateYHCoupon(requestBodyMap,packageCodeCF,provider);
            			if(resultMap != null){
            				List<StoreCouponEntity> storeCouponEntityList = storeCouponDao.findYHCoupon(packageCodeCF);
                			for (int i = 0; i < storeCouponEntityList.size(); i++) {
                				StoreCouponEntity storeCouponEntity = storeCouponEntityList.get(i);
                				//获取激活码
                				String couponNum = storeCouponEntity.getCouponNum();

                				ImportCardEntity importCardEntity = new ImportCardEntity();
                				importCardEntity.setCardNum(couponNum);
                				importCardDao.updateInitialCard(importCardEntity);
            				}
                			
                			//多家服务商同时请求 一家失败即为失败 返回上游 更新服务包以及卡券  是否有效字段
                    		Map<String, Object> requestMap = new HashMap<String, Object>();
                			requestMap.put("packageCodeCF", packageCodeCF);
                			requestMap.put("isDelete", 1);
                			requestMap.put("activateCode", "");
                			storePackageDao.updateByParam(requestMap);
                			storeCouponDao.updateByParam(requestMap);
                			
            				//医护类卡券生成异常 
                            jsonResult.put("resultCode", "01");
                    		jsonResult.put("resultDesc", "医护类卡券生成异常："+resultMap.get("resultDesc"));
                            return jsonResult;
            			}
            		}else{
            			//根据服务商和服务类型 查询增值服务服务商信息表和增值服务服务商请求地址配置表 获取请求url
                		String url = apiConfigUtil.getApiConfig(provider, "dispense_package");
                		
                		//根据上游发券接口请求报文拼装下游服务包发送报文
                    	Map<String,String> map = packageRequestMsg(requestBodyMap,provider,formCode);
                    	
                    	String requestMsg = JSON.toJSONString(map);
                    	
            			logger.info("请求下游发放服务包接口接口url ==" + url);
            			logger.info("请求下游发放服务包接口请求报文 ==" + requestMsg);
            			
                    	// 调用下游服务包发送接口
                    	String packageResult = HttpClientUtil.sendHttpPost(url, requestMsg, new HashMap<String, String>(){{
                            put("Content-Type", "application/json;charset=UTF-8");
                        }});        	
                    	JSONObject resultObject = JSONObject.parseObject(packageResult);

                    	String message = PublicUtil.isNotEmpty(resultObject.get("resultDesc")) ? resultObject.get("resultDesc").toString() : null;
                    	
                    	logger.error("下游发放服务包返回信息 : "+message);
                    	if(!"成功".equals(message)){
                    		List<StoreCouponEntity> storeCouponEntityList = storeCouponDao.findYHCoupon(packageCodeCF);
                			for (int i = 0; i < storeCouponEntityList.size(); i++) {
                				StoreCouponEntity storeCouponEntity = storeCouponEntityList.get(i);
                				//获取激活码
                				String couponNum = storeCouponEntity.getCouponNum();

                				ImportCardEntity importCardEntity = new ImportCardEntity();
                				importCardEntity.setCardNum(couponNum);
                				importCardDao.updateInitialCard(importCardEntity);
            				}
                			
                			//多家服务商同时请求 一家失败即为失败 返回上游 更新服务包以及卡券  是否有效字段
                    		Map<String, Object> requestMap = new HashMap<String, Object>();
                			requestMap.put("packageCodeCF", packageCodeCF);
                			requestMap.put("isDelete", 1);
                			requestMap.put("activateCode", "");
                			storePackageDao.updateByParam(requestMap);
                			storeCouponDao.updateByParam(requestMap);
                			
                    		
                    		//下游接口返回失败  返回失败原因给上游 
                            jsonResult.put("resultCode", "01");
                    		jsonResult.put("resultDesc", "请求下游服务商："+providerCN+" 发放服务包接口失败，失败原因："+message);
                            return jsonResult;
                    	}
                    	//第三方机构接口标识
                    	String apiSource = PublicUtil.isNotEmpty(requestBodyMap.get("apiSource")) ? requestBodyMap.get("apiSource").toString() : null; 
                    	//根据下游发送服务包接口返回的报文，保存服务包和卡券信息
                    	logger.error("保存服务包和卡券信息");
                    	String serviceItemCode = PublicUtil.isNotEmpty(requestBodyMap.get("service_item_code")) ? requestBodyMap.get("service_item_code").toString() : null;
                    	insertPackageAndCoupon(packageResult, orderId, serviceItemCode, carNo, customerName, phone, apiSource,provider, packageCodeCF);
            		}
    			}
            	//所有下游全部返回成功，才保存服务包订单信息
            	logger.error("保存服务包订单信息");
            	
            	
            	insertPackageOrder(requestBodyMap,packageCodeCF);
            	
            	storePackageList = storePackageDao.queryByOrderId(orderId);
            	jsonResult = genResponseMsg(storePackageList,orderId,"0000");
			} catch (Exception e) {
    			
    			List<StoreCouponEntity> storeCouponEntityList = storeCouponDao.findYHCoupon(packageCodeCF);
    			for (int i = 0; i < storeCouponEntityList.size(); i++) {
    				StoreCouponEntity storeCouponEntity = storeCouponEntityList.get(i);
    				//获取激活码
    				String couponNum = storeCouponEntity.getCouponNum();

    				ImportCardEntity importCardEntity = new ImportCardEntity();
    				importCardEntity.setCardNum(couponNum);
    				importCardDao.updateInitialCard(importCardEntity);
				}
    			
    			//多家服务商同时请求 一家失败即为失败 返回上游 更新服务包以及卡券  是否有效字段
        		Map<String, Object> requestMap = new HashMap<String, Object>();
    			requestMap.put("packageCodeCF", packageCodeCF);
    			requestMap.put("isDelete", 1);
    			requestMap.put("activateCode", "");
    			storePackageDao.updateByParam(requestMap);
    			storeCouponDao.updateByParam(requestMap);
			}
        	
        	
        }else{//订单已保存则返回已生成的卡券信息 
        	jsonResult = genResponseMsg(storePackageList,orderId,"1007");
        }
		
        return jsonResult;        
    }
    
    /**
     * 拼装下游服务包发送接口请求报文
     * @param requestBodyMap 上游发券接口请求体
     */
    public HashMap<String, String> packageRequestMsg(Map<String, Object> requestBodyMap,String provider,String formCode){
    	
    	//客户号
    	String customerNo = PublicUtil.isNotEmpty(requestBodyMap.get("customerNo")) ? requestBodyMap.get("customerNo").toString() : null; 
    	
    	//客户姓名
    	String customerName = PublicUtil.isNotEmpty(requestBodyMap.get("name")) ? requestBodyMap.get("name").toString() : null;
    	
    	//客户手机号
    	String customerMobilePhone = PublicUtil.isNotEmpty(requestBodyMap.get("phone")) ? requestBodyMap.get("phone").toString() : null;
    	
    	//机构code
    	String orgCode = PublicUtil.isNotEmpty(requestBodyMap.get("org_code")) ? requestBodyMap.get("org_code").toString() : null;
    	
    	//服务包类型	 0 无指定所有者,1 客户号指定所有者,2 手机号指定所有者（默认0）
    	String package_type = "0";
    	
    	//服务包生效时间	
    	String eff_date = PublicUtil.isNotEmpty(requestBodyMap.get("service_eff_date")) ? requestBodyMap.get("service_eff_date").toString() : null;
    	String package_eff_date = "";
    	if(eff_date!=null){
    		package_eff_date = DateUtil.DateToString(DateUtil.stringToDate(eff_date, "yyyy-MM-dd HH:mm:ss"),"yyyy-MM-dd");
    	}
    	
    	//车牌号
    	String carNo = PublicUtil.isNotEmpty(requestBodyMap.get("carNo")) ? requestBodyMap.get("carNo").toString() : null; 
    	
    	//服务包是否立即生效   根据生效日期判断是否立即生效
    	String package_is_alive = "0";
    	if(!"".equals(package_eff_date)){
    		String currentDate = DateUtil.DateToString(new Date(), "yyyy-MM-dd");
    		if(currentDate.compareTo(package_eff_date)>=0){
    			package_is_alive = "1";
    		}
    	}
    	
    	//第三方流水号	
    	String 	third_query_id = PublicUtil.isNotEmpty(requestBodyMap.get("sn")) ? requestBodyMap.get("sn").toString() : null;
    	
    	//签名类型
    	String signType = "MD5";
    	
    	ServerPackageParam serverPackageParam = new ServerPackageParam();
    	serverPackageParam.setFormCode(formCode);
    	
    	String source = apiConfigUtil.getApiConfig(provider, "disponse_code");
		serverPackageParam.setSource(source);
		
		String apiSource = apiConfigUtil.getApiConfig(provider, "disponse_thr_code");
		serverPackageParam.setApiSource(apiSource);
		if(customerNo!=null){
			serverPackageParam.setCustomerNo(customerNo);
		}
		if(customerName!=null){
			serverPackageParam.setCustomerName(customerName);
		}
		if(customerMobilePhone!=null){
			serverPackageParam.setCustomerMobilePhone(customerMobilePhone);
		}
		
		serverPackageParam.setPackage_type(package_type);
		serverPackageParam.setPackage_is_alive(package_is_alive);
		serverPackageParam.setCreate_order_isopen("1");
		serverPackageParam.setSignType(signType);
		serverPackageParam.setThird_query_id(third_query_id);
		if(orgCode!=null){
			serverPackageParam.setUseCityCode("02-"+orgCode);
		}
		serverPackageParam.setCarId(carNo);
		
		HashMap<String, String> beanToStringMap = (HashMap<String, String>) XYSdSignUtil.beanToStringMap(serverPackageParam);
    	
    	
    	//签名  待生成
    	String sign = "";
    	try {
    		String redeemcodeSignKey = apiConfigUtil.getApiConfig(provider, "package_sign");
    		sign = XYSdSignUtil.generateSignature(beanToStringMap, redeemcodeSignKey, signType);
    		logger.info("请求下游验签sign值："+sign);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
    	beanToStringMap.put("sign", sign);
    	return beanToStringMap;
    }
    
    /**
     * cardList 查询获得未使用激活码集合
     * count 医护类卡券数量
     * 更新卡券激活码表  防止并发 需将所有已更新的数据全部回复最初状态 
     * 再次查询  直至查询到符合标准的集合 如果返回集合长度为0 则提示上游
     */
    public List<ImportCardEntity> getNonUseCard(List<ImportCardEntity> cardList, List<String> nonUseParamsList){
    	List<ImportCardEntity> list = new ArrayList<ImportCardEntity>();
    	for (int i = 0; i < cardList.size(); i++) {
			ImportCardEntity importCardEntity = cardList.get(i);
			int updateNum = importCardDao.updateCardByEntity(importCardEntity);
			if(updateNum==1){
				list.add(importCardEntity);
			}else{
				break;
			}
		}
    	if(list.size()==nonUseParamsList.size()){
    		return list;
    	}else{
    		for (int i = 0; i < list.size(); i++) {
    			ImportCardEntity importCardEntity = cardList.get(i);
    			importCardDao.updateInitialCard(importCardEntity);
			}
    		//查询count个导入的卡券编码与激活兑换码   获取后将对应的记录更新已使用状态
    		List<ImportCardEntity> initialCardList = importCardDao.queryNonUseCard(nonUseParamsList);
    		
    		if(initialCardList!=null){
    			if(initialCardList.size()<nonUseParamsList.size()){
					return new ArrayList<ImportCardEntity>();
        		}else{
        			return getNonUseCard(initialCardList, nonUseParamsList);
        		}
    		}else{
    			return new ArrayList<ImportCardEntity>();
    		}
    	}
    }
    
    /**
     * 根据上游请求报文新增服务包订单数据
     * @param requestBodyMap  上游请求报文
     * @param packageCodeCF  车服服务包 编码 对应多个服务包编码  获取卡券个数
     */
    public void insertPackageOrder(Map<String, Object> requestBodyMap,String packageCodeCF){
    	StoreOrderEntity storeOrderEntity = new StoreOrderEntity();
    	//订单号
    	String orderId = PublicUtil.isNotEmpty(requestBodyMap.get("orderId")) ? requestBodyMap.get("orderId").toString() : null; 
    	storeOrderEntity.setOrderId(orderId);
    	
    	//机构编码
    	String source = PublicUtil.isNotEmpty(requestBodyMap.get("source")) ? requestBodyMap.get("source").toString() : null; 
    	storeOrderEntity.setSource(source);
    	
    	//第三方机构接口标识
    	String apiSource = PublicUtil.isNotEmpty(requestBodyMap.get("apiSource")) ? requestBodyMap.get("apiSource").toString() : null; 
    	storeOrderEntity.setApiSource(apiSource);
    	
    	//客户号
    	String customerNo = PublicUtil.isNotEmpty(requestBodyMap.get("customerNo")) ? requestBodyMap.get("customerNo").toString() : null; 
    	storeOrderEntity.setCustomerNo(customerNo);
    	
    	//客户姓名
    	String customerName = PublicUtil.isNotEmpty(requestBodyMap.get("name")) ? requestBodyMap.get("name").toString() : null;
    	storeOrderEntity.setName(customerName);
    	
    	//客户手机号
    	String customerMobilePhone = PublicUtil.isNotEmpty(requestBodyMap.get("phone")) ? requestBodyMap.get("phone").toString() : null;
    	storeOrderEntity.setPhone(customerMobilePhone);
    	
    	//车牌号
    	String carNo = PublicUtil.isNotEmpty(requestBodyMap.get("carNo")) ? requestBodyMap.get("carNo").toString() : null;	
    	storeOrderEntity.setCarNo(carNo);
    	
    	//车架号
    	String frameNo = PublicUtil.isNotEmpty(requestBodyMap.get("frameNo")) ? requestBodyMap.get("frameNo").toString() : null;
    	storeOrderEntity.setFrameNo(frameNo);
    	
    	//机构关联的服务
    	String serviceItemCode = PublicUtil.isNotEmpty(requestBodyMap.get("service_item_code")) ? requestBodyMap.get("service_item_code").toString() : null;
    	storeOrderEntity.setServiceItemCode(serviceItemCode);
    	
    	//卡券数量
    	String couponNum = PublicUtil.isNotEmpty(requestBodyMap.get("coupon_num")) ? requestBodyMap.get("coupon_num").toString() : null;
    	storeOrderEntity.setCouponNum(Integer.parseInt(couponNum));
    	
    	//生效日期
    	String effDate = PublicUtil.isNotEmpty(requestBodyMap.get("service_eff_date")) ? requestBodyMap.get("service_eff_date").toString() : null;
    	storeOrderEntity.setEffDate(DateUtil.stringToDate(effDate, "yyyy-MM-dd HH:mm:ss"));
    	
    	//失效日期
    	String expDate = PublicUtil.isNotEmpty(requestBodyMap.get("service_exp_date")) ? requestBodyMap.get("service_exp_date").toString() : null;
    	storeOrderEntity.setExpDate(DateUtil.stringToDate(expDate, "yyyy-MM-dd HH:mm:ss"));
    	
    	//机构code
    	String orgCode = PublicUtil.isNotEmpty(requestBodyMap.get("org_code")) ? requestBodyMap.get("org_code").toString() : null;
    	storeOrderEntity.setOrgCode(orgCode);
    	
    	//机构名称
    	String orgName = PublicUtil.isNotEmpty(requestBodyMap.get("org_name")) ? requestBodyMap.get("org_name").toString() : null;
    	storeOrderEntity.setOrgName(orgName);
    	
    	//机构父code
    	String orgParentCode = PublicUtil.isNotEmpty(requestBodyMap.get("org_parent_code")) ? requestBodyMap.get("org_parent_code").toString() : null;
    	storeOrderEntity.setOrgParentCode(orgParentCode);
    	
    	//流水号
    	String sn = PublicUtil.isNotEmpty(requestBodyMap.get("sn")) ? requestBodyMap.get("sn").toString() : null;
    	storeOrderEntity.setSn(sn);
    	
    	//积分商城商品id
    	String pid = PublicUtil.isNotEmpty(requestBodyMap.get("pid")) ? requestBodyMap.get("pid").toString() : null;
    	
    	Map<String, Object> params = new HashMap<String, Object>();
    	params.put("packageCodeCF", packageCodeCF);
    	List<StoreCouponEntity> storeCouponEntityList = storeCouponDao.findListByParam(params);
		storeOrderEntity.setCouponNum(storeCouponEntityList.size());
    	
    	storeOrderEntity.setPid(pid);
    	storeOrderEntity.setIsDelete(0);
    	storeOrderEntity.setCreateTime(new Date());
    	storeOrderEntity.setCreater("system");
    	storeOrderEntity.setUpdateTime(new Date());
    	storeOrderEntity.setUpdater("system");
    	storeOrderDao.insert(storeOrderEntity);
    }
    
    /**
     * 根据下游服务包发送接口返回的报文新增服务包和卡券信息
     * @param packageResult  下游返回报文
     * @param orderId  绑定订单号
     * @param serviceItemCode  服务包配置configcode
     * @param carNo  绑定车牌号
     * @param customerName  客户姓名
     * @param apiSource  渠道方
     * @param provider  服务商主键
     * @param packageCodeCF  车服服务包编码
     */
    public void insertPackageAndCoupon(String packageResult,String orderId,String serviceItemCode,String carNo,String customerName,String phone,String apiSource,String provider,String packageCodeCF){
    	JSONObject packageResultObject = JSONObject.parseObject(packageResult);
    	
    	//获取服务包信息
    	String serverPackage = PublicUtil.isNotEmpty(packageResultObject.get("serverPackage")) ? packageResultObject.get("serverPackage").toString() : null;
		JSONObject serverPackageObject = JSONObject.parseObject(serverPackage);
		StorePackageEntity storePackageEntity = new StorePackageEntity();
		
		//车服服务包编码
		storePackageEntity.setPackageCodeCF(packageCodeCF);
		
		//服务包编码
		String packageCode = PublicUtil.isNotEmpty(serverPackageObject.get("package_code")) ? serverPackageObject.get("package_code").toString() : null;
		storePackageEntity.setPackageCode(packageCode);
		
		Map<String, Object> reqVo = new HashMap<String, Object>();
		reqVo.put("configCode", serviceItemCode);
		List<StorePackageConfigEntity> storePackageConfigEntityList = storePackageConfigDao.queryPackageConfig(reqVo);
		String packageName = "";
		if(storePackageConfigEntityList!=null&&storePackageConfigEntityList.size()>0){
			packageName = storePackageConfigEntityList.get(0).getConfigName();
		}
		storePackageEntity.setPackageName(packageName);
		
		//默认未兑换
		storePackageEntity.setStatus("0");
		
		//服务包所有者
		String packageOwner = PublicUtil.isNotEmpty(serverPackageObject.get("package_owner")) ? serverPackageObject.get("package_owner").toString() : null;
		storePackageEntity.setOwner(packageOwner);
		
		//服务包生成订单数量
		String couponCount = PublicUtil.isNotEmpty(serverPackageObject.get("coupon_count")) ? serverPackageObject.get("coupon_count").toString() : null;
		storePackageEntity.setCouponCount(String.valueOf(Integer.parseInt(couponCount)));
		
		//服务包创建时间
		String createTime = PublicUtil.isNotEmpty(serverPackageObject.get("create_time")) ? serverPackageObject.get("create_time").toString() : null;
		storePackageEntity.setCreateDate(DateUtil.stringToDate(createTime, "yyyy-MM-dd HH:mm:ss"));
		
		//渠道方
		storePackageEntity.setChannel(apiSource);
		
		//服务商
		storePackageEntity.setServer(provider);
		
		//生效日期
    	String effDate = PublicUtil.isNotEmpty(serverPackageObject.get("package_eff_date")) ? serverPackageObject.get("package_eff_date").toString() : null;
    	storePackageEntity.setEffDate(DateUtil.stringToDate(effDate+" 00:00:00", "yyyy-MM-dd HH:mm:ss"));
    	
    	//失效日期
    	String expDate = PublicUtil.isNotEmpty(serverPackageObject.get("package_exp_date")) ? serverPackageObject.get("package_exp_date").toString() : null;
    	storePackageEntity.setExpDate(DateUtil.stringToDate(expDate+" 23:59:59", "yyyy-MM-dd HH:mm:ss"));
    	
    	//序列码类型 
    	storePackageEntity.setSeqType("2");
    	//归属订单
    	storePackageEntity.setOrderId(orderId);
    	//绑定车牌号
    	storePackageEntity.setCarNo(carNo);
    	storePackageEntity.setSendDate(new Date());
    	storePackageEntity.setIsDelete(0);
    	storePackageEntity.setCreateTime(new Date());
    	storePackageEntity.setCreater("system");
    	storePackageEntity.setUpdateTime(new Date());
    	storePackageEntity.setUpdater("system");
    	storePackageDao.insert(storePackageEntity);
    	
		//获取卡券信息
		String coupons = PublicUtil.isNotEmpty(packageResultObject.get("coupons")) ? packageResultObject.get("coupons").toString() : null;
		JSONArray JSONArray = JSONObject.parseArray(coupons);
		for (int i = 0; i < JSONArray.size(); i++) {
			JSONObject couponObject = JSONArray.getJSONObject(i);
			StoreCouponEntity storeCouponEntity = new StoreCouponEntity();
			
			//卡券编码
			String couponNum = PublicUtil.isNotEmpty(couponObject.get("coupon_num")) ? couponObject.get("coupon_num").toString() : null;
			storeCouponEntity.setCouponNum(couponNum);
			
			//加密串（用于生成二维码）
			String couponEncrypt = PublicUtil.isNotEmpty(couponObject.get("coupon_encrypt")) ? couponObject.get("coupon_encrypt").toString() : null;
			storeCouponEntity.setEncrypt(couponEncrypt);
			
			//服务类型
			String activityId = PublicUtil.isNotEmpty(couponObject.get("activity_id")) ? couponObject.get("activity_id").toString() : null;
			storeCouponEntity.setActivityId(activityId);
			
			//生效日期
			String couponEffDate = PublicUtil.isNotEmpty(couponObject.get("coupon_eff_date")) ? couponObject.get("coupon_eff_date").toString() : null;
	    	Date couponEffTime = DateUtil.stringToDate(couponEffDate+" 00:00:00", "yyyy-MM-dd HH:mm:ss");
			storeCouponEntity.setEffDate(couponEffTime);
	    	
	    	//失效日期
	    	String couponExpDate = PublicUtil.isNotEmpty(couponObject.get("coupon_exp_date")) ? couponObject.get("coupon_exp_date").toString() : null;
	    	Date couponExpTime = DateUtil.stringToDate(couponExpDate+" 23:59:59", "yyyy-MM-dd HH:mm:ss");
	    	storeCouponEntity.setExpDate(couponExpTime);
			//卡券状态  根据生效日期 和失效日期判断是否生效或者失效
	    	Date currentTime = new Date();
	    	if(currentTime.compareTo(couponEffTime)<0){
	    		//待生效
	    		storeCouponEntity.setStatus("0");
	    	}
	    	
	    	if(couponEffTime.compareTo(currentTime)<0&&currentTime.compareTo(couponExpTime)<0){
	    		//生效
	    		storeCouponEntity.setStatus("1");
	    	}
	    	if(couponExpTime.compareTo(currentTime)<0){
	    		//失效
	    		storeCouponEntity.setStatus("2");
	    	}
			
			//渠道方
			storeCouponEntity.setChannel(apiSource);
			//服务商
			storeCouponEntity.setServer(provider);
			//车服服务包编码
			storeCouponEntity.setPackageCodeCF(packageCodeCF);
			//归属服务包
			storeCouponEntity.setPackageCode(packageCode);
			storeCouponEntity.setPackageName(packageName);
			//归属订单
			storeCouponEntity.setOrderId(orderId);
			//绑定车牌号
			storeCouponEntity.setCarNo(carNo);
			storeCouponEntity.setCustomerName(customerName);
			//绑定手机
			storeCouponEntity.setPhone(phone);
			
	    	storeCouponEntity.setIsDelete(0);
	    	storeCouponEntity.setCreateTime(new Date());
	    	storeCouponEntity.setCreater("system");
	    	storeCouponEntity.setUpdateTime(new Date());
	    	storeCouponEntity.setUpdater("system");
	    	storeCouponDao.insert(storeCouponEntity);
	    	
		}
		
    }
    
    public JSONObject genResponseMsg(List<StorePackageEntity> storePackageList,String orderId,String resultCode){
    	JSONObject jsonResult = new JSONObject();
    	
    	Date effDate = storePackageList.get(0).getEffDate();
    	Date expDate = storePackageList.get(0).getExpDate();
    	for (int i = 1; i < storePackageList.size(); i++) {
    		StorePackageEntity storePackageEntity = storePackageList.get(i);
    		Date tempEffDate = storePackageEntity.getEffDate();
    		Date tempExpDate = storePackageEntity.getExpDate();
    		
    		if(tempEffDate.compareTo(effDate)<0){
    			effDate = tempEffDate;
    		}
    		
    		if(expDate.compareTo(tempExpDate)<0){
    			expDate = tempExpDate;
    		}
		}
    	
    	
    	StorePackageEntity storePackageEntity = storePackageList.get(0);
    	String packageCodeCF = storePackageEntity.getPackageCodeCF();
    	
    	Map<String, Object> params = new HashMap<String, Object>();
    	params.put("packageCodeCF", packageCodeCF);
    	//根据归属服务包 获取该服务包下所有卡券
    	List<StoreCouponEntity> storeCouponEntityList = storeCouponDao.findListByParam(params);
    	
    	StoreOrderEntity storeOrderEntity = storeOrderDao.queryByOrderId(orderId);
    	
    	jsonResult.put("resultCode", resultCode);
		jsonResult.put("resultDesc", "成功");
		JSONArray serverPackageJsonArr = new JSONArray();

		JSONObject serverPackageJsonResult = new JSONObject();
		serverPackageJsonResult.put("card_code", packageCodeCF);
		serverPackageJsonResult.put("service_item_code", storeOrderEntity.getServiceItemCode());
		Map<String, Object> param = new HashMap<String, Object>();
		param.put("configCode", storeOrderEntity.getServiceItemCode());
		List<StorePackageConfigEntity> storePackageConfigEntityList = storePackageConfigDao.queryPackageConfig(param);
		if(storePackageConfigEntityList!=null&&storePackageConfigEntityList.size()>0){
			serverPackageJsonResult.put("service_item_name", storePackageConfigEntityList.get(0).getConfigName());
		}
		serverPackageJsonResult.put("service_eff_date", DateUtil.DateToString(effDate));
		serverPackageJsonResult.put("service_exp_date", DateUtil.DateToString(expDate));
		serverPackageJsonResult.put("create_time", DateUtil.DateToString(storePackageEntity.getCreateDate()));
		serverPackageJsonResult.put("is_package", "1");
		
		JSONArray childPackageJsonArr = new JSONArray();
		for (int j = 0; j < storeCouponEntityList.size(); j++) {
			JSONObject childPackageJsonResult = new JSONObject();
			StoreCouponEntity storeCouponEntity = storeCouponEntityList.get(j);
			childPackageJsonResult.put("card_code", storeCouponEntity.getCouponNum());
			String activityId = storeCouponEntity.getActivityId();
			childPackageJsonResult.put("service_item_code", activityId);
			DictCodeEntity dictCodeEntity = new DictCodeEntity();
			dictCodeEntity.setTypeCode("activityName");
			dictCodeEntity.setCode(activityId);
			List<DictCodeEntity> dictCodeEntityList = dictCodeDao.getdictCodeList(dictCodeEntity);
			if(dictCodeEntityList.size()>0){
				DictCodeEntity dictCode = dictCodeEntityList.get(0);
				childPackageJsonResult.put("service_item_name", dictCode.getValue());
			}
			childPackageJsonResult.put("service_eff_date", DateUtil.DateToString(storeCouponEntity.getEffDate()));
			childPackageJsonResult.put("service_exp_date", DateUtil.DateToString(storeCouponEntity.getExpDate()));
			childPackageJsonResult.put("create_time", DateUtil.DateToString(storePackageEntity.getCreateDate()));
			childPackageJsonArr.add(childPackageJsonResult);
		}
		serverPackageJsonResult.put("child_package", childPackageJsonArr);
		serverPackageJsonArr.add(serverPackageJsonResult);
		
		
		jsonResult.put("serverPackage", serverPackageJsonArr);
		
		return jsonResult;
    }
    
    /**
     * 生成医护类卡券并保存数据库
     * @param requestBodyMap 上游请求报文
     * @param packageCodeCF  车服服务包编码
     * @param provider		   服务商
     * @return
     */
    public HashMap<String, String> generateYHCoupon(Map<String, Object> requestBodyMap,String packageCodeCF,String provider){
    	HashMap<String, String> reusltMap = new HashMap<String, String>();
    	
    	//生成自定义医护类服务包编码
    	String packageCodeYH = "ZXHY"+DateUtil.DateToString(new Date(), "yyyyMMddHHmmssSSS");
    	
    	String serviceItemCode = PublicUtil.isNotEmpty(requestBodyMap.get("service_item_code")) ? requestBodyMap.get("service_item_code").toString() : null;
    	//服务包生效日期
    	String eff_date = PublicUtil.isNotEmpty(requestBodyMap.get("service_eff_date")) ? requestBodyMap.get("service_eff_date").toString() : null;
    	//服务包生效日期
    	String exp_date = PublicUtil.isNotEmpty(requestBodyMap.get("service_exp_date")) ? requestBodyMap.get("service_exp_date").toString() : null;
    	//订单号
    	String orderId = PublicUtil.isNotEmpty(requestBodyMap.get("orderId")) ? requestBodyMap.get("orderId").toString() : null;
    	//车牌号
    	String carNo = requestBodyMap.get("carNo").toString();
    	//第三方机构接口标识
    	String apiSource = PublicUtil.isNotEmpty(requestBodyMap.get("apiSource")) ? requestBodyMap.get("apiSource").toString() : null; 
    	
    	//获取服务包类型  判断其中是否包含医护类
    	Map<String,Object> activityParam = new HashMap<String,Object>();
    	activityParam.put("configCode", serviceItemCode);
    	activityParam.put("provider", provider);
    	//查询该服务包下所有的医护类服务  医护类服务个数代表卡券个数  
    	List<StoreActivityConfigEntity> storeActivityConfigEntityList = storeActivityConfigDao.queryActivityConfig(activityParam);
    	//医护类卡券个数
    	int count = 0;
    	if(storeActivityConfigEntityList!=null){
    		count = storeActivityConfigEntityList.size();
    	}
    	
		StorePackageEntity storePackageEntity = new StorePackageEntity();
		
		//车服服务包编码
		storePackageEntity.setPackageCodeCF(packageCodeCF);
		
		//服务包编码
		storePackageEntity.setPackageCode(packageCodeYH);
		
		Map<String, Object> reqVo = new HashMap<String, Object>();
		reqVo.put("configCode", serviceItemCode);
		List<StorePackageConfigEntity> storePackageConfigEntityList = storePackageConfigDao.queryPackageConfig(reqVo);
		String packageName = "";
		if(storePackageConfigEntityList!=null&&storePackageConfigEntityList.size()>0){
			packageName = storePackageConfigEntityList.get(0).getConfigName();
		}
		storePackageEntity.setPackageName(packageName);
		
		//默认未兑换
		storePackageEntity.setStatus("0");
		
		//服务包生成订单数量
		storePackageEntity.setCouponCount(String.valueOf(count));
		
		
		//服务包创建时间
		storePackageEntity.setCreateDate(new Date());
		
		//渠道方
		storePackageEntity.setChannel(apiSource);
		
		//服务商
		storePackageEntity.setServer(provider);
		
		//生效日期
    	storePackageEntity.setEffDate(DateUtil.stringToDate(eff_date, "yyyy-MM-dd HH:mm:ss"));
    	
    	//失效日期
    	storePackageEntity.setExpDate(DateUtil.stringToDate(exp_date, "yyyy-MM-dd HH:mm:ss"));
    	
    	//序列码类型 
    	storePackageEntity.setSeqType("2");
    	//归属订单
    	storePackageEntity.setOrderId(orderId);
    	//绑定车牌号
    	storePackageEntity.setCarNo(carNo);
    	storePackageEntity.setSendDate(new Date());
    	storePackageEntity.setIsDelete(0);
    	storePackageEntity.setCreateTime(new Date());
    	storePackageEntity.setCreater("system");
    	storePackageEntity.setUpdateTime(new Date());
    	storePackageEntity.setUpdater("system");
    	storePackageDao.insert(storePackageEntity);
    	
    	
    	//该服务包存在医护类卡券
    	if(count>0){
    		//查询count个导入的卡券编码与激活兑换码   获取后将对应的记录更新已使用状态
    		List<String> nonUseParamsList = new ArrayList<String>();
    		for (int i = 0; i < storeActivityConfigEntityList.size(); i++) {
    			nonUseParamsList.add(storeActivityConfigEntityList.get(i).getActivityCode());
			}
    		
    		List<ImportCardEntity> cardList = importCardDao.queryNonUseCard(nonUseParamsList);
    		if(cardList!=null){
    			if(cardList.size()<count){
    				//未使用的卡券编码与激活兑换码 小于count  直接返回失败
    				reusltMap.put("resultCode", "01");
    				reusltMap.put("resultDesc", "服务包请求异常，服务数据缺失");
    				
    				String requestMsg = JSON.toJSONString(requestBodyMap);
    				String responeMsg = JSON.toJSONString(reusltMap);
    				String logDataId = UUID.randomUUID().toString().replace("-", "");
    		    	DriverInterfaceLogEntity driverInterfaceLogEntity = new DriverInterfaceLogEntity();
    		    	driverInterfaceLogEntity.setDataId(logDataId);
    		    	driverInterfaceLogEntity.setOrderNo(orderId);
    		    	driverInterfaceLogEntity.setOrderId("");
    		    	driverInterfaceLogEntity.setInterfaceName("医护类卡券发放接口");
    		    	driverInterfaceLogEntity.setRequestTime(new Date());
    		    	driverInterfaceLogEntity.setRequestBody(requestMsg);
    		    	driverInterfaceLogEntity.setResponseBody(responeMsg);
    		    	driverInterfaceLogEntity.setResponseTime(new Date());
    		    	driverInterfaceLogEntity.setCreateTime(new Date());
    		    	driverInterfaceLogDao.insert(driverInterfaceLogEntity);
    		    	
					return reusltMap;
        		}else{
        			//更新获取的卡券编码与激活兑换码 为已使用状态
        			List<ImportCardEntity> NonUseCardList =  getNonUseCard(cardList,nonUseParamsList);
        			//便利卡券编码与激活兑换码  新增卡券记录
        			for (int i = 0; i < NonUseCardList.size(); i++) {
        				ImportCardEntity importCardEntity = NonUseCardList.get(i);
        				StoreActivityConfigEntity storeActivityConfigEntity = storeActivityConfigEntityList.get(i);
						//卡券码
						String couponNum = importCardEntity.getCardNum();
						//激活码
						String activateCode = importCardEntity.getActivateCode();
						StoreCouponEntity couponEntity = new StoreCouponEntity();
						
						couponEntity.setCouponNum(couponNum);
						//根据服务包的生效日期 判断是否生效
				    	String package_eff_date = "";
				    	if(eff_date!=null){
				    		package_eff_date = DateUtil.DateToString(DateUtil.stringToDate(eff_date, "yyyy-MM-dd HH:mm:ss"),"yyyy-MM-dd");
				    	}
				    	//服务包是否立即生效   根据生效日期判断是否立即生效
				    	String package_is_alive = "0";
				    	if(!"".equals(package_eff_date)){
				    		String currentDate = DateUtil.DateToString(new Date(), "yyyy-MM-dd");
				    		if(currentDate.compareTo(package_eff_date)>=0){
				    			package_is_alive = "1";
				    		}
				    	}
						couponEntity.setStatus(package_is_alive);
						couponEntity.setChannel(apiSource);
						couponEntity.setServer(provider);
						//暂存 待下游发券接口返回成功后 更新为服务包编码
						couponEntity.setPackageCode(packageCodeYH);
						couponEntity.setPackageCodeCF(packageCodeCF);
						
						couponEntity.setPackageName(packageName);
						couponEntity.setOrderId(orderId);
						
						//上游请求服务包生效日期
						Date effDate = DateUtil.stringToDate(eff_date, "yyyy-MM-dd HH:mm:ss");
						couponEntity.setEffDate(effDate);
						//服务包生效日期+卡券有效期天数
						Date expDate = DateUtil.addDate(effDate, storeActivityConfigEntity.getValidityPeriod());
						couponEntity.setExpDate(expDate);
						
						//客户手机号
				    	String customerMobilePhone = PublicUtil.isNotEmpty(requestBodyMap.get("phone")) ? requestBodyMap.get("phone").toString() : null;
						couponEntity.setPhone(customerMobilePhone);
						
						couponEntity.setCarNo(carNo);
						couponEntity.setActivityId(importCardEntity.getActivityId());
						couponEntity.setActivateCode(activateCode);
						couponEntity.setIsDelete(0);
						Date currentDate = new Date();
						couponEntity.setCreateTime(currentDate);
						couponEntity.setCreater("system");
						couponEntity.setUpdateTime(currentDate);
						couponEntity.setUpdater("system");
						storeCouponDao.insert(couponEntity);
					}
        		}
    		}else{
    			//数据库中不存在未使用的卡券编码与激活兑换码  直接返回失败
				reusltMap.put("resultCode", "01");
				reusltMap.put("resultDesc", "服务包请求异常，服务数据缺失");
				
				String requestMsg = JSON.toJSONString(requestBodyMap);
				String responeMsg = JSON.toJSONString(reusltMap);
				String logDataId = UUID.randomUUID().toString().replace("-", "");
		    	DriverInterfaceLogEntity driverInterfaceLogEntity = new DriverInterfaceLogEntity();
		    	driverInterfaceLogEntity.setDataId(logDataId);
		    	driverInterfaceLogEntity.setOrderNo(orderId);
		    	driverInterfaceLogEntity.setOrderId("");
		    	driverInterfaceLogEntity.setInterfaceName("医护类卡券发放接口");
		    	driverInterfaceLogEntity.setRequestTime(new Date());
		    	driverInterfaceLogEntity.setRequestBody(requestMsg);
		    	driverInterfaceLogEntity.setResponseBody(responeMsg);
		    	driverInterfaceLogEntity.setResponseTime(new Date());
		    	driverInterfaceLogEntity.setCreateTime(new Date());
		    	driverInterfaceLogDao.insert(driverInterfaceLogEntity);
		    	
				return reusltMap;
    		}
    	}
		return null;
    }
}
